package io.renren.enums;

import lombok.Getter;

import java.util.*;

public enum ModelType {
    LORA(1,"LORA"),
    CHECKPOINT(2,"CHECKPOINT");

    @Getter
    private int code;
    @Getter
    private String name;

    ModelType(int code,String name){
        this.code = code;
        this.name = name;
    }

    public static ModelType getEnumByCode(int code) {
        for (ModelType modelType : ModelType.values()) {
            if (modelType.getCode() == code) {
                return modelType;
            }
        }
        return null;
    }

    public static String getNameByCode(int code) {
        for (ModelType modelType : ModelType.values()) {
            if (modelType.getCode() == code) {
                return modelType.getName();
            }
        }
        return null;
    }

    public static int getCodeByName(String name) {
        for (ModelType modelType : ModelType.values()) {
            if (modelType.getName().equals(name)) {
                return modelType.getCode();
            }
        }
        return 0;
    }

    // 返回所有枚举值的列表
    public static List<Map<String,String>> getMap() {
        List<Map<String,String>> list = new ArrayList<>();
        for (ModelType modelType : ModelType.values()) {
            Map<String, String> map = new HashMap<>();
            map.put("code", String.valueOf(modelType.getCode()));
            map.put("name", modelType.getName());
            list.add(map);
        }
        return list;
    }

}
